ShadowDrawable

This class is a thin wrapper around the library's core draw functionalities, allowing its shadows to be drawn manually without having to use the core module directly.

Clipped instances with irregular shapes on API levels 30+ must have the outline Path set manually using the setClipPathProvider function. This is analogous to setting a ViewPathProvider on a target View.

This drawable suffers from the same potential clip alignment glitch that the View solution does on API levels 24..28. The forceLayer property is available to address the issue as described for View.forceShadowLayer.

All ShadowDrawable instances created with an ownerView should call dispose. This is technically not necessary for the @RequiresApi(29) ones, but it is still safe to call dispose on those instances. Use after disposal is not an automatic Exception, but it is not advised, and there is no guaranteed behavior.

The user is responsible for invalidating the current draw whenever a property's value is changed. Failure to do so can result in a few different possible defects, depending on the specific setup, including misaligned clip regions, stale draws, etc.

This drawable's bounds do not affect the shadow's size or shape. Those are initialized from the properties of the Outline passed to setOutline, and are modifiable afterward with the relevant functions and properties; e.g, setPosition, translationX, scaleY, etc.

The color compat functionality is exposed here through the colorCompat property, which is set to black by default, disabling the compat tinting. Setting any non-black color enables color compat, and the ambientColor and spotColor values are then ignored.

The color compat functionality requires a View object. Instances created with the @RequiresApi(29) constructor simply ignore colorCompat.

The Drawable class's required setColorFilter override is a no-op.

When using color compat, the shadows are clipped to the drawable's bounds. Also, due to differences in the native framework, all shadows on API levels 24..28 are clipped to the drawable's bounds.

Constructors

Link copied to clipboard
constructor(ownerView: View, isClipped: Boolean)

The base constructor for all API levels requires an ownerView in order to be able to hook into the hardware-accelerated draw routine.

@RequiresApi(value = 29)
constructor(isClipped: Boolean)

At API level 29, an owner View is not required, but color compat is unavailable for these instances.

Properties

Link copied to clipboard

The color that the compat mechanism uses to tint the shadow. The default value is black (#FF000000), which disables the tint. If any other color is set, the compat mechanism takes over, and the ambient and spot values are ignored.

Link copied to clipboard
Link copied to clipboard

Flag to indicate whether the library shadow should always be composited through a layer, whether or not color compat is in use.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun dispose()

Releases any active internal resources.

Link copied to clipboard
open override fun draw(canvas: Canvas)
Link copied to clipboard
open override fun getAlpha(): Int

Analogous to RenderNode#getAlpha(), but returns an Int to conform to Drawable's API.

Link copied to clipboard
fun getMatrix(outMatrix: Matrix)
Link copied to clipboard
open override fun getOpacity(): Int
Link copied to clipboard
Link copied to clipboard
open override fun invalidateSelf()
Link copied to clipboard
open override fun setAlpha(alpha: Int)

Analogous to RenderNode#setAlpha(), but takes an Int to conform to Drawable's API.

Link copied to clipboard
fun setClipPathProvider(provider: (Path) -> Unit?)

Sets the function through which to provide irregular Paths for clipping on API levels 30 and above.

Link copied to clipboard
open override fun setColorFilter(colorFilter: ColorFilter?)
Link copied to clipboard
fun setOutline(outline: Outline)
Link copied to clipboard
fun setPosition(left: Int, top: Int, right: Int, bottom: Int)